package Vue;

import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.Color;
import javax.swing.JComboBox;

import Controleur.LoadSource;
import Controleur.RendreVeloBtnValiderListener;
import Controleur.RendreVeloComboListener;
import java.awt.Point;
import java.awt.Dimension;
import java.util.ArrayList;

/**
 * Définit la fenetre de retour de vélo
 */
public class RendreVelo extends JDialog{
	
	
	
	private static final long serialVersionUID = 1L;
	/** Label le client n'a pas loué de vélo */
	JLabel lblLeClientNa = new JLabel("Le client n'a pas lou\u00E9 de v\u00E9lo.");
	/** Bouton validant le retour du vélo */
	JButton btnValider;
	/** Label indiquant que la station est pleine */
	JLabel lblLaStationEst = new JLabel("La station est pleine.");
	/** Liste deroulante des clients */
	JComboBox comboBoxClient;
	/** Liste deroulante des stations */
	JComboBox comboBoxStation;
	
	/**
	 * Instancie la fenetre de retour de vélo
	 */
	public RendreVelo() {
		setResizable(false);
		setModal(true);
		setMinimumSize(new Dimension(430, 300));
		setLocation(new Point(200, 200));
		
		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JLabel lblRendreUnVlo = new JLabel("Rendre un v\u00E9lo");
		lblRendreUnVlo.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblRendreUnVlo.setBounds(153, 11, 123, 28);
		panel.add(lblRendreUnVlo);
		
		JLabel lblClient = new JLabel("Client");
		lblClient.setBounds(51, 83, 46, 14);
		panel.add(lblClient);
		
		JLabel lblStation = new JLabel("Station");
		lblStation.setBounds(51, 131, 46, 14);
		panel.add(lblStation);
		
		btnValider = new JButton("Valider");
		btnValider.setEnabled(false);
		btnValider.setForeground(new Color(0, 128, 0));
		btnValider.setFont(new Font("Tahoma", Font.BOLD, 12));
		
		btnValider.addActionListener(new RendreVeloBtnValiderListener(this));
		
		btnValider.setBounds(167, 209, 89, 23);
		panel.add(btnValider);
		

		// Remplissage de la combobox
		ArrayList<Object> clients = LoadSource.getClients();
		comboBoxClient = new JComboBox(clients.toArray());
		
		comboBoxClient.setBounds(123, 80, 101, 20);
		panel.add(comboBoxClient);
		comboBoxClient.addActionListener(new RendreVeloComboListener(this));
		
		// Remplissage de la combobox
		ArrayList<Object> stations = LoadSource.getStations();
		comboBoxStation = new JComboBox(stations.toArray());
		
		comboBoxStation.addActionListener(new RendreVeloComboListener(this));
		
		comboBoxStation.setBounds(119, 128, 89, 20);
		panel.add(comboBoxStation);
		
				

		comboBoxStation.setBounds(123, 128, 100, 20);
		panel.add(comboBoxStation);
		
		
		lblLeClientNa.setVisible(false);
		lblLeClientNa.setBounds(130, 157, 208, 14);
		panel.add(lblLeClientNa);
		
		lblLaStationEst.setVisible(false);
		lblLaStationEst.setBounds(130, 182, 146, 14);
		panel.add(lblLaStationEst);


		// On selectionne la première ligne
		if(comboBoxClient.getItemCount() != 0)
			comboBoxClient.setSelectedIndex(0);

		// On selectionne la première ligne
		if(comboBoxStation.getItemCount() != 0)
			comboBoxStation.setSelectedIndex(0);
	}



	
	/**
	 * Méthode fermant la fenetre
	 */
	public void close(){this.dispose();}
	
	/**
	 * Getter liste deroulante station
	 * @return comboBoxStation
	 */
	public JComboBox getComboBoxStation() {
		return comboBoxStation;
	}
	/**
	 * Getter liste deroulante client
	 * @return comboBoxCLient
	 */
	public JComboBox getComboBoxClient() {
		return comboBoxClient;
	}
	/**
	 * Getter label client n'a pas loue de velo
	 * @return lblLeClientNa
	 */
	public JLabel getLblLeClientNa() {
		return lblLeClientNa;
	}
	/**
	 * Getter label station pleine
	 * @return lblLaStationEst
	 */
	public JLabel getLblLaStationEst() {
		return lblLaStationEst;
	}
	/**
	 * Getter du bouton valider
	 * @return BtnValider
	 */
	public JButton getBtnValider() {
		return btnValider;
	}
	
	
}


